package com.huang.domain;

import com.huang.enums.ResultStatus;
import lombok.Getter;
import lombok.ToString;

import java.io.Serializable;

@Getter
@ToString
public final class ResultObject<T> implements Serializable {

    private Integer retCode;

    private String retMsg;

    private T data;

    private ResultObject() {}

    public static ResultObject success() {
        ResultObject result = new ResultObject<>();
        result.retCode = ResultStatus.SUCCESS.getCode();
        result.retMsg = ResultStatus.SUCCESS.getTipStr();
        return result;
    }
    public static <T> ResultObject<T> success(T data) {
        ResultObject<T> result = new ResultObject<>();
        result.retCode = ResultStatus.SUCCESS.getCode();
        result.retMsg = ResultStatus.SUCCESS.getTipStr();
        result.data = data;
        return result;
    }

    public static <T> ResultObject<T> fail(ResultStatus status) {
        ResultObject<T> result = new ResultObject<>();
        result.retCode = status.getCode();
        result.retMsg = status.getTipStr();
        return result;
    }

    public static <T> ResultObject<T> fail(Integer retCode, String retMsg) {
        ResultObject<T> result = new ResultObject<>();
        result.retCode = retCode;
        result.retMsg = retMsg;
        return result;
    }
}
